package com.lxl.hadoop.order;

import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * @Author lixilin
 * @Date 2022/1/1 9:54
 * @Description
 */
public class OrderBean implements WritableComparable<OrderBean> {

    private Integer orderCode;
    private Double money;

    public OrderBean() {
        super();
    }

    public OrderBean(Integer orderCode, Double money) {
        super();
        this.orderCode = orderCode;
        this.money = money;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeInt(orderCode);
        out.writeDouble(money);

    }

    @Override
    public void readFields(DataInput in) throws IOException {
        this.orderCode = in.readInt();
        this.money = in.readDouble();
    }

    @Override
    public int compareTo(OrderBean o) {
        // 先根据 订单号升序排序,再根据money降序排序
        if (this.orderCode ==o.orderCode) {
            if (this.money ==o.money) {
                return 0;
            }
            return this.money > o.money ? -1 : 1;
        }
        return this.orderCode > o.orderCode ? 1 : -1;
    }

    public Integer getOrderCode() {
        return orderCode;
    }

    public void setOrderCode(Integer orderCode) {
        this.orderCode = orderCode;
    }

    public Double getMoney() {
        return money;
    }

    public void setMoney(Double money) {
        this.money = money;
    }

    @Override
    public String toString() {
        return orderCode + "\t" + money;
    }

}
